<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>文件上传</title>
<link type="text/css" rel="stylesheet" href="<c:url value='/resources/uploadify/uploadify.css' />" />
<script type="text/javascript" src="<c:url value='/resources/js/jquery-1.8.3.js'/>"></script>
<script type="text/javascript" src="<c:url value='/resources/uploadify/jquery.uploadify.min.js'/>"></script>

<script type="text/javascript">

	$(function (){
		
		var uploadify_onSelectError = function(file, errorCode, errorMsg) {
	        var msgText = "上传失败\n";  
	        switch (errorCode) {  
	            case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:  
	                //this.queueData.errorMsg = "每次最多上传 " + this.settings.queueSizeLimit + "个文件";  
	                msgText += "每次最多上传 " + this.settings.queueSizeLimit + "个文件";  
	                break;  
	            case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:  
	                msgText += "文件大小超过限制( " + this.settings.fileSizeLimit + " )";  
	                break;  
	            case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:  
	                msgText += "文件大小为0";  
	                break;  
	            case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:  
	                msgText += "文件格式不正确，仅限 " + this.settings.fileTypeExts;  
	                break;  
	            default:  
	                msgText += "错误代码：" + errorCode + "\n" + errorMsg;  
	        }  
	        alert(msgText);  
	    }
		
	    var uploadify_onUploadError = function(file, errorCode, errorMsg, errorString) {  
	        // 手工取消不弹出提示  
	        if (errorCode == SWFUpload.UPLOAD_ERROR.FILE_CANCELLED || errorCode == SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED) {  
	            return;  
	        }
	        var msgText = "上传失败\n";  
	        switch (errorCode) {  
	            case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:  
	                msgText += "HTTP 错误\n" + errorMsg;  
	                break;  
	            case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:  
	                msgText += "上传文件丢失，请重新上传";  
	                break;  
	            case SWFUpload.UPLOAD_ERROR.IO_ERROR:  
	                msgText += "IO错误";  
	                break;  
	            case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:  
	                msgText += "安全性错误\n" + errorMsg;  
	                break;  
	            case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:  
	            	alert(1);
	                msgText += "每次最多上传 " + $(file).settings.uploadLimit + "个";  
	                break;  
	            case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:  
	                msgText += errorMsg;  
	                break;  
	            case SWFUpload.UPLOAD_ERROR.SPECIFIED_FILE_ID_NOT_FOUND:  
	                msgText += "找不到指定文件，请重新操作";  
	                break;  
	            case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:  
	                msgText += "参数错误";  
	                break;  
	            default:  
	                msgText += "文件:" + file.name + "\n错误码:" + errorCode + "\n"  
	                        + errorMsg + "\n" + errorString;  
	        }  
	        alert(msgText);  
		    return parameters; 
	    }  
	    
	    var uploadify_onSelect = function(){  
	 	   
		}
	
		var uploadify_onUploadSuccess = function(file, data, response) {  
		    alert(file.name + "\n\n" + response + "\n\n" + data);  
		}
		
		var uploadify_config = {  
			    uploader : '<c:url value="testUploadify.html" />',  
			    swf : '<c:url value="/resources/uploadify/uploadify.swf" />',  
			    //buttonImage : '/images/uploadify-button.png',  
			    //cancelImg : '/images/uploadify-cancel.png',  
			    //'wmode' : 'transparent',  
			    //'removeTimeout' : 0,  
			    width : 80,  
			    height : 30,  
			    auto : false, // 文件选中后是否自动提交
			    multi : true, // 多选
			    uploadLimit : 6, // 允许上传的最大个数
			    buttonText : '上传',  
			    //hideButton : true,  
			    fileTypeExts : '*.png;*.jpg;*.jpeg',  
			    fileSizeLimit : '2MB',  
			    //fileTypeDesc : 'Image Files',  
			    formData : {"action": "upload", "sid" : ""},  
			    overrideEvents : [ 'onDialogClose', 'onUploadSuccess', 'onUploadError', 'onSelectError' ],  
			    onSelect : uploadify_onSelect,  
			    onSelectError : uploadify_onSelectError,  
			    onUploadError : uploadify_onUploadError,  
			    onUploadSuccess : uploadify_onUploadSuccess  
			}
		
		
		$("#file_upload").uploadify(uploadify_config); 
	});




	$(function() {
		
		//点击按钮触发上传
		function startUpload() {
			alert($('#file_upload').uploadifySettings('queueSize'));
			//$('#file_upload').uploadify('upload', '*');
		}
	});






</script>

</head>
<body>
	<div class="control-group">
		<label class="control-label">文档</label>
		<div class="controls">
			<div id="queue"></div>
			<input id="file_upload" name="fileAttach" type="file">
		</div>
	</div>
	<div class="form-actions">
		<button type="button" class="btn btn-primary" onclick="startUpload()">上 传</button>
	</div>
</body>
</html>
